package com.hope.mychat.core.rule;

import com.hope.mychat.core.MyChat;
import com.hope.mychat.domain.vo.Message;
import com.hope.mychat.util.DateUtil;

import javax.websocket.EncodeException;
import java.io.IOException;

/**
 * @author ZWH
 */
public class Ping extends Base {
    public Ping(Message message) {
        super(message);
    }

    public void handle() throws IOException, EncodeException {
        // 心跳消息只设置一个时间
        message.setCreateTime(DateUtil.getCurSecond());
        // 获取当前用户websocket session
        sessionForm = MyChat.LIVING_SESSIONS_CACHE.get(message.getFromId());
        // 心跳回复
        if (sessionForm == null) {
            return;
        }
        sessionForm.getBasicRemote().sendObject(message);
    }
}
